home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / FILESAVE.C < prev    next >
Text File  |  1992-05-14  |  3KB  |  99 lines

  1. /************************************************************************************/
  2. /*    FileSaveProc                                                                    */
  3. /*                                                                                    */
  4. /*    This proc is used by menu items Save and Save As.  Return code is set to 1 for    */
  5. /*    all errors, except a Cancel choice out of FSPutFile.  It is set to 2 for that.    */
  6. /************************************************************************************/
  7.  
  8. #include "MyHeaders.h"
  9.  
  10. int FileSaveProc (Boolean SaveAsFlag)
  11. {
  12.     int            FSRetCode = 0;
  13.     Rect        dlogRect;
  14.     int            rectHeight, rectWidth;
  15.     int            newH, newV;
  16.     int            itemHit;                                /* return from modal dialog    */
  17.     
  18.     
  19.     myDlogPtr = GetNewDialog (putDlgID, NIL, (WindowPtr) -1);    /* get the dialog    */
  20.  
  21.     dlogRect = (*myDlogPtr).portRect;                    /* position dlog on desktop    */
  22.     rectHeight = dlogRect.bottom - dlogRect.top;        
  23.     rectWidth = dlogRect.right - dlogRect.left;
  24.     newH = (screenBits.bounds.right - rectWidth) * .50;    /* centered    horizonally        */
  25.     newH += 2;                                            /* jive it in                */
  26.     if (newH < 10)                                        /* (not less than 10)        */
  27.         newH = 10;
  28.     newV = ((screenBits.bounds.bottom - 30                /* vertical position        */
  29.              - rectHeight)* (.33)) + 30;                /*   one-third down            */
  30.     if (newV < 30)                                        /* (not less than 30)        */
  31.         newV = 30;
  32.  
  33.  
  34.     if ((windTbl[windSub].windPathRefNum == 0)
  35.             || (SaveAsFlag == TRUE))
  36.         {        
  37.         GetWTitle (windTbl[windSub].windPtr, &workStr255);    /* name for text box    */
  38.         SetPt (&workPoint, newH,newV);                        /* upper left corner    */
  39.         SFPutFile (workPoint, NIL, &workStr255, NIL, &workReply);
  40.         if (workReply.good == FALSE)                        /* if cancel            */
  41.             {
  42.             FSRetCode = 2;                                    /* set cancel ret code    */
  43.             goto ENDING;                                    /* but get out anyway    */
  44.             }
  45.         if (((workReply.vRefNum != windTbl[windSub].windReply.vRefNum)    /* if diff.    */
  46.                     || (workReply.fName != windTbl[windSub].windReply.fName))
  47.                 && (SaveAsFlag == TRUE))                    /* and it is saveAs        */
  48.             {
  49.             if (windTbl[windSub].windPathRefNum != 0)
  50.                 {
  51.                 workRC = FSClose (windTbl[windSub].windPathRefNum);    /* close old    */
  52.                 if (workRC != noErr)
  53.                     {
  54.                     FSRetCode = 1;
  55.                     goto ENDING;
  56.                     }
  57.                 windTbl[windSub].windPathRefNum = 0;        /* indicate file closed    */
  58.                 }
  59.             }
  60.         windTbl[windSub].windReply = workReply;                /* store new SF info    */
  61.         workRC = Create (&windTbl[windSub].windReply.fName,    /* try creating new file*/
  62.                 windTbl[windSub].windReply.vRefNum, 'chAS','TEXT');
  63.         if ((workRC != noErr)                                /* if an error other    */
  64.                 && (workRC != dupFNErr))                    /* than name already is    */
  65.             {
  66.             FSRetCode = 1;                                    /* indicate error        */
  67.             goto ENDING;                                    /* and leave            */
  68.             }
  69.         workRC = FSOpen (&windTbl[windSub].windReply.fName,    /* open the new file    */
  70.                 windTbl[windSub].windReply.vRefNum,
  71.                 &windTbl[windSub].windPathRefNum);
  72.         switch (workRC)
  73.             {
  74.             case (noErr):
  75.             break;
  76.             
  77.             case (opWrErr):                                    /* zero path which is    */
  78.                 windTbl[windSub].windPathRefNum = 0;        /* from somewhere else    */
  79.                 FSRetCode = 1;                                /* set bad ret code        */
  80.                 goto ENDING;                                /* get out                */
  81.             break;
  82.             
  83.             default:
  84.                 FSRetCode = 1;                                /* set bad ret code        */
  85.                 goto ENDING;                                /* get out                */
  86.             break;
  87.             }
  88.         SetWTitle (windTbl[windSub].windPtr,                /* name to wind title    */
  89.                 windTbl[windSub].windReply.fName);
  90.         }
  91.     
  92.     worklong =                                            /* transfer data to file    */
  93.         WriteFromTE(windTbl[windSub].windPathRefNum,
  94.         windTbl[windSub].windTEH[0]);
  95.     windTbl[windSub].windTEChanged = FALSE;                /* reset the changed flag    */
  96.     
  97. ENDING:
  98.     return    FSRetCode;
  99. }